from fastapi.security.api_key import APIKeyHeader
from fastapi import Security, HTTPException, status

from price_analysis.core.config import settings

api_key_header = APIKeyHeader(name="access_token", auto_error=False)


async def get_api_key(api_key: str = Security(api_key_header)) -> str:
    if not api_key == settings.api_key:
        raise HTTPException(status_code=status.HTTP_403_FORBIDDEN,
                            detail="Нет доступа")

    return api_key
